﻿using Microsoft.Practices.Unity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Tippelde.Services.Dtos;
using Tippelde.Services.Events;
using Tippelde.Services.News;
using Tippelde.Web.Models.Home;

namespace Tippelde.Web.Controllers
{
    public class HomeController : Controller
    {
        [Dependency]
        public INewsManager NewsManager { get; set; }

        [Dependency]
        public IEventManager EventManager { get; set; }

        public ActionResult Index()
        {
            var model = new HomeIndexModel
            {
                News = NewsManager.GetTopNews(User.Identity.IsAuthenticated ? User.Identity.Name : null, 5),
                Events = new List<EventHeaderData>()
            };
            if (User.Identity.IsAuthenticated)
            {
                try
                {
                    model.Events = EventManager.GetUpcomingEventHeadersForUser(User.Identity.Name, 5);
                }
                catch (Exception ex) { }
            }
            return View(model);
        }


        public ActionResult Contact()
        {
            ViewBag.Message = "Kapcsolat.";

            return View();
        }

        public ActionResult Error()
        {
            throw new Exception("Ez egy hiba oldal lesz");
        }
    }
}